package edu.dkakunsi.ta.client.form;

import edu.dkakunsi.ta.client.entity.Department;
import edu.dkakunsi.ta.client.entity.Izin;
import edu.dkakunsi.ta.client.entity.IzinArray;
import edu.dkakunsi.ta.client.entity.Lembur;
import edu.dkakunsi.ta.client.entity.LemburArray;
import edu.dkakunsi.ta.client.entity.Pegawai;
import edu.dkakunsi.ta.client.entity.PegawaiArray;
import edu.dkakunsi.ta.client.entity.Presensi;
import edu.dkakunsi.ta.client.entity.PresensiArray;
import edu.dkakunsi.ta.client.exception.ClientNotAuthenticatedException_Exception;
import edu.dkakunsi.ta.client.exception.EntityException_Exception;
import edu.dkakunsi.ta.client.exception.GeneralException_Exception;
import edu.dkakunsi.ta.client.exception.PegawaiNotExistException_Exception;
import edu.dkakunsi.ta.client.exception.PegawaiNotPresentException_Exception;
import edu.dkakunsi.ta.client.util.Constant;
import edu.dkakunsi.ta.client.util.ServiceManager;
import java.net.MalformedURLException;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.table.DefaultTableModel;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.ws.soap.SOAPFaultException;

/**
 *
 * @author dkakunsi
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MainFrame
     */
    public MainFrame() {
        initComponents();
    }

        /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jtpMain = new javax.swing.JTabbedPane();
        jpHadir = new javax.swing.JPanel();
        lblNipHadir = new javax.swing.JLabel();
        jspNipHadir = new javax.swing.JScrollPane();
        txtNipHadir = new javax.swing.JTextPane();
        btnOKHadir = new javax.swing.JButton();
        jspDaftarHadir = new javax.swing.JScrollPane();
        tblDaftarHadir = new javax.swing.JTable();
        jpIzin = new javax.swing.JPanel();
        lblNipIzin = new javax.swing.JLabel();
        jspNipIzin = new javax.swing.JScrollPane();
        txtNipIzin = new javax.swing.JTextPane();
        btnOKIzin = new javax.swing.JButton();
        jspDaftarIzin = new javax.swing.JScrollPane();
        tblDaftarIzin = new javax.swing.JTable();
        jpLembur = new javax.swing.JPanel();
        lblNipLembur = new javax.swing.JLabel();
        jspNipLembur = new javax.swing.JScrollPane();
        txtNipLembur = new javax.swing.JTextPane();
        btnOKLembur = new javax.swing.JButton();
        jspDaftarLembur = new javax.swing.JScrollPane();
        tblDaftarLembur = new javax.swing.JTable();
        jpData = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblData = new javax.swing.JTable();
        btnTambah = new javax.swing.JButton();
        btnSimpan = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();
        btnCari = new javax.swing.JButton();
        txtNipData = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtNama = new javax.swing.JTextField();
        txtAlamat = new javax.swing.JTextField();
        txtSkpd = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblTanggal = new javax.swing.JLabel();
        lblBulan = new javax.swing.JLabel();
        lblTahun = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jtpMain.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jtpMain.setName(""); // NOI18N
        jtpMain.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtpMainMouseClicked(evt);
            }
        });

        jpHadir.setName("hadir"); // NOI18N
        jpHadir.setLayout(null);

        lblNipHadir.setText("NIP");
        jpHadir.add(lblNipHadir);
        lblNipHadir.setBounds(20, 20, 25, 30);

        txtNipHadir.setName("txtNipHadir"); // NOI18N
        jspNipHadir.setViewportView(txtNipHadir);

        jpHadir.add(jspNipHadir);
        jspNipHadir.setBounds(70, 20, 193, 30);

        btnOKHadir.setText("Isi Daftar Hadir");
        btnOKHadir.setName("btnIsiHadir"); // NOI18N
        btnOKHadir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKHadirActionPerformed(evt);
            }
        });
        jpHadir.add(btnOKHadir);
        btnOKHadir.setBounds(280, 20, 160, 30);

        tblDaftarHadir.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "NIP", "NAMA", "TANGGAL", "JAM DATANG", "JAM PULANG"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblDaftarHadir.setName("tblHadir"); // NOI18N
        jspDaftarHadir.setViewportView(tblDaftarHadir);

        jpHadir.add(jspDaftarHadir);
        jspDaftarHadir.setBounds(10, 90, 580, 260);

        jtpMain.addTab("Daftar Hadir", jpHadir);

        jpIzin.setName("izin"); // NOI18N
        jpIzin.setLayout(null);

        lblNipIzin.setText("NIP");
        jpIzin.add(lblNipIzin);
        lblNipIzin.setBounds(20, 20, 25, 30);

        txtNipIzin.setName("txtNipIzin"); // NOI18N
        txtNipIzin.setPreferredSize(new java.awt.Dimension(6, 25));
        jspNipIzin.setViewportView(txtNipIzin);

        jpIzin.add(jspNipIzin);
        jspNipIzin.setBounds(70, 20, 193, 30);

        btnOKIzin.setText("Isi Daftar Izin");
        btnOKIzin.setName("btnIsiIzin"); // NOI18N
        btnOKIzin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKIzinActionPerformed(evt);
            }
        });
        jpIzin.add(btnOKIzin);
        btnOKIzin.setBounds(280, 20, 160, 30);

        tblDaftarIzin.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "NIP", "NAMA", "JAM MASUK", "JAM KELUAR"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblDaftarIzin.setName("tblIsi"); // NOI18N
        jspDaftarIzin.setViewportView(tblDaftarIzin);

        jpIzin.add(jspDaftarIzin);
        jspDaftarIzin.setBounds(10, 90, 580, 260);

        jtpMain.addTab("Daftar Izin", jpIzin);

        jpLembur.setName("lembur"); // NOI18N
        jpLembur.setLayout(null);

        lblNipLembur.setText("NIP");
        jpLembur.add(lblNipLembur);
        lblNipLembur.setBounds(20, 20, 25, 30);

        txtNipLembur.setName("txtNipLembur"); // NOI18N
        txtNipLembur.setPreferredSize(new java.awt.Dimension(4, 25));
        jspNipLembur.setViewportView(txtNipLembur);

        jpLembur.add(jspNipLembur);
        jspNipLembur.setBounds(70, 20, 193, 30);

        btnOKLembur.setText("Isi Daftar Lembur");
        btnOKLembur.setName("btnIsiLembur"); // NOI18N
        btnOKLembur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOKLemburActionPerformed(evt);
            }
        });
        jpLembur.add(btnOKLembur);
        btnOKLembur.setBounds(280, 20, 160, 30);

        tblDaftarLembur.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "NIP", "NAMA", "JUMLAH"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblDaftarLembur.setName("tblLembur"); // NOI18N
        jspDaftarLembur.setViewportView(tblDaftarLembur);

        jpLembur.add(jspDaftarLembur);
        jspDaftarLembur.setBounds(10, 90, 580, 260);

        jtpMain.addTab("Daftar Lembur", jpLembur);

        jpData.setName("data"); // NOI18N

        tblData.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "NIP", "Nama", "Alamat"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tblData.setName("tblData"); // NOI18N
        jScrollPane1.setViewportView(tblData);

        btnTambah.setText("Tambah");
        btnTambah.setName("btnTambah"); // NOI18N
        btnTambah.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTambahActionPerformed(evt);
            }
        });

        btnSimpan.setText("Simpan");
        btnSimpan.setName("btnSimpan"); // NOI18N
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnHapus.setText("Hapus");
        btnHapus.setName("btnHapus"); // NOI18N
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        btnCari.setText("Cari");
        btnCari.setName("btnCari"); // NOI18N
        btnCari.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariActionPerformed(evt);
            }
        });

        txtNipData.setName("txtNipData"); // NOI18N

        jLabel1.setText("NIP");

        jLabel2.setText("Nama");

        txtNama.setName("txtNama"); // NOI18N

        txtAlamat.setName("txtAlamat"); // NOI18N

        txtSkpd.setEditable(false);
        txtSkpd.setName("txtSkpd"); // NOI18N

        jLabel3.setText("Alamat");

        jLabel4.setText("SKPD");

        javax.swing.GroupLayout jpDataLayout = new javax.swing.GroupLayout(jpData);
        jpData.setLayout(jpDataLayout);
        jpDataLayout.setHorizontalGroup(
            jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDataLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpDataLayout.createSequentialGroup()
                        .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(22, 22, 22)
                        .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtSkpd, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtAlamat, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNama, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtNipData)))
                    .addGroup(jpDataLayout.createSequentialGroup()
                        .addGap(0, 28, Short.MAX_VALUE)
                        .addComponent(btnTambah)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSimpan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnHapus)))
                .addGap(18, 18, 18)
                .addComponent(btnCari)
                .addContainerGap())
        );
        jpDataLayout.setVerticalGroup(
            jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpDataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCari)
                    .addComponent(txtNipData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(18, 18, 18)
                .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSkpd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jpDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnTambah)
                    .addComponent(btnSimpan)
                    .addComponent(btnHapus))
                .addContainerGap(140, Short.MAX_VALUE))
        );

        jtpMain.addTab("Data Pegawai", jpData);

        lblTanggal.setText("TGL");

        lblBulan.setText("BLN");

        lblTahun.setText("THN");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jtpMain)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lblTanggal)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblBulan)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblTahun)
                .addGap(61, 61, 61))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTanggal)
                    .addComponent(lblBulan)
                    .addComponent(lblTahun))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jtpMain, javax.swing.GroupLayout.PREFERRED_SIZE, 400, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jtpMain.getAccessibleContext().setAccessibleName("Daftar Izin");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnOKHadirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKHadirActionPerformed
        try {
            String nip = this.txtNipHadir.getText();
            String message = new ServiceManager().getPresensiService().daftar(nip, code);
            
            JOptionPane.showMessageDialog(this, message);
            loadDaftarHadir();
        } catch (EntityException_Exception | PegawaiNotPresentException_Exception | ClientNotAuthenticatedException_Exception | PegawaiNotExistException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getFault().getFaultString());
        }
    }//GEN-LAST:event_btnOKHadirActionPerformed

    private void btnOKIzinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKIzinActionPerformed
        try {
            String nip = this.txtNipIzin.getText();
            String message = new ServiceManager().getIzinService().daftar(nip, code);

            JOptionPane.showMessageDialog(this, message);
            loadDaftarIzin();
        } catch (EntityException_Exception | PegawaiNotPresentException_Exception | ClientNotAuthenticatedException_Exception | PegawaiNotExistException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getFault().getFaultString());
        }
    }//GEN-LAST:event_btnOKIzinActionPerformed

    private void btnOKLemburActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKLemburActionPerformed
        try {
            String nip = this.txtNipLembur.getText();
            String message = new ServiceManager().getLemburService().daftar(nip, code);
            JOptionPane.showMessageDialog(this, message);
            loadDaftarLembur();
        } catch (GeneralException_Exception | EntityException_Exception | PegawaiNotPresentException_Exception | ClientNotAuthenticatedException_Exception | PegawaiNotExistException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getFault().getFaultString());
        }
    }//GEN-LAST:event_btnOKLemburActionPerformed

    private void btnCariActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariActionPerformed
        try {
            String nip = this.txtNipData.getText();
            pegawai = new ServiceManager().getPegawaiService().getById(nip);
            this.txtNama.setText(pegawai.getNama());
            this.txtAlamat.setText("Alamat");
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        } catch (EntityException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnCariActionPerformed

    private void btnTambahActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTambahActionPerformed
        this.txtNipData.setText("");
        this.txtNama.setText("");
        this.txtAlamat.setText("");
    }//GEN-LAST:event_btnTambahActionPerformed

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        try {
            String nip = this.txtNipData.getText();
            String nama = this.txtNama.getText();
            String alamat = this.txtAlamat.getText();
            
            pegawai = new Pegawai();
            pegawai.setNip(nip);
            pegawai.setNama(nama);
            pegawai.setDepartment(Constant.getDepartment());
            new ServiceManager().getPegawaiService().save(pegawai);
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        } catch (EntityException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnSimpanActionPerformed

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
        try {
            new ServiceManager().getPegawaiService().delete(pegawai);
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        } catch (EntityException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnHapusActionPerformed

    private void jtpMainMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtpMainMouseClicked
        JTabbedPane p = (JTabbedPane)evt.getSource();

        try {
            switch(p.getSelectedComponent().getName()) {
                case "hadir" : loadDaftarHadir();
                    break;
                case "izin" : loadDaftarIzin();
                    break;
                case "lembur" : loadDaftarLembur();
                    break;
                case "data" : loadDaftarPegawai();
                    break;
                default : JOptionPane.showMessageDialog(this, "No Component");
                    break;
            }
        } catch(EntityException_Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        } catch (SOAPFaultException ex) {
            JOptionPane.showMessageDialog(this, ex.getFault().getFaultString());
        }
    }//GEN-LAST:event_jtpMainMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCari;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnOKHadir;
    private javax.swing.JButton btnOKIzin;
    private javax.swing.JButton btnOKLembur;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JButton btnTambah;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jpData;
    private javax.swing.JPanel jpHadir;
    private javax.swing.JPanel jpIzin;
    private javax.swing.JPanel jpLembur;
    private javax.swing.JScrollPane jspDaftarHadir;
    private javax.swing.JScrollPane jspDaftarIzin;
    private javax.swing.JScrollPane jspDaftarLembur;
    private javax.swing.JScrollPane jspNipHadir;
    private javax.swing.JScrollPane jspNipIzin;
    private javax.swing.JScrollPane jspNipLembur;
    private javax.swing.JTabbedPane jtpMain;
    private javax.swing.JLabel lblBulan;
    private javax.swing.JLabel lblNipHadir;
    private javax.swing.JLabel lblNipIzin;
    private javax.swing.JLabel lblNipLembur;
    private javax.swing.JLabel lblTahun;
    private javax.swing.JLabel lblTanggal;
    private javax.swing.JTable tblDaftarHadir;
    private javax.swing.JTable tblDaftarIzin;
    private javax.swing.JTable tblDaftarLembur;
    private javax.swing.JTable tblData;
    private javax.swing.JTextField txtAlamat;
    private javax.swing.JTextField txtNama;
    private javax.swing.JTextField txtNipData;
    private javax.swing.JTextPane txtNipHadir;
    private javax.swing.JTextPane txtNipIzin;
    private javax.swing.JTextPane txtNipLembur;
    private javax.swing.JTextField txtSkpd;
    // End of variables declaration//GEN-END:variables
    private String code = "client";
    private Pegawai pegawai;
    
    private void loadDaftarHadir() throws EntityException_Exception {
        try {
            String[] str = {"NIP", "Nama", "Tanggal", "Jam Masuk", "Jam Keluar"};
            DefaultTableModel tabModel = new DefaultTableModel(null, str);
            this.tblDaftarHadir.setModel(tabModel);

            String nip = this.txtNipHadir.getText();
            PresensiArray arr = new ServiceManager().getPresensiService().getByNip(nip);
            Pegawai pgw = new ServiceManager().getPegawaiService().getById(nip);

            for(Presensi p : arr.getItem()) {
                String tanggal = toDateString(p.getId().getTanggal());
                String masuk = toTimeString(p.getMasuk());
                String keluar = toTimeString(p.getKeluar());
                
                Object[] data = {nip, pgw.getNama(), tanggal, masuk, keluar};
                tabModel.addRow(data);
            }
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        }
    }
    
    private void loadDaftarIzin() throws EntityException_Exception {
        try {
            String[] str = {"NIP", "Nama", "Tanggal", "Jam Keluar", "Jam Masuk"};
            DefaultTableModel tabModel = new DefaultTableModel(null, str);
            this.tblDaftarIzin.setModel(tabModel);

            String nip = this.txtNipIzin.getText();
            IzinArray arr = new ServiceManager().getIzinService().getByNip(nip);
            Pegawai p = new ServiceManager().getPegawaiService().getById(nip);

            for(Izin i : arr.getItem()) {
                String tanggal = toDateString(i.getId().getTanggal());
                String masuk = toTimeString(i.getMasuk());
                String keluar = toTimeString(i.getKeluar());

                Object[] data = {nip, p.getNama(), tanggal, keluar, masuk};
                tabModel.addRow(data);
            }
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        }
    }
    
    private void loadDaftarLembur() throws EntityException_Exception {
        try {
            String[] str = {"NIP", "Nama", "Tanggal", "Jumlah Lembur"};
            DefaultTableModel tabModel = new DefaultTableModel(null, str);
            this.tblDaftarLembur.setModel(tabModel);

            String nip = this.txtNipLembur.getText();
            LemburArray arr = new ServiceManager().getLemburService().getByNip(nip);
            Pegawai p = new ServiceManager().getPegawaiService().getById(nip);

            for(Lembur l : arr.getItem()) {
                String tanggal = toDateString(l.getId().getTanggal());

                Object[] data = {nip, p.getNama(), tanggal, l.getJumlah()};
                tabModel.addRow(data);
            }
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        }
    }
    
    private void loadDaftarPegawai() throws EntityException_Exception {
        try {
            String[] str = {"NIP", "Nama", "Alamat"};
            DefaultTableModel tabModel = new DefaultTableModel(null, str);
            this.tblData.setModel(tabModel);

            String nip = this.txtNipData.getText();
            PegawaiArray arr = new ServiceManager().getPegawaiService().getAll();

            for(Pegawai p : arr.getItem()) {
                Object[] data = {p.getNip(), p.getNama(), "Alamat Saya"};
                tabModel.addRow(data);
            }
        } catch (MalformedURLException ex) {
            JOptionPane.showMessageDialog(this, "Internal Error");
        }
    }
    
    private String toTimeString(XMLGregorianCalendar c) {
        if(c != null)
            return c.getHour() +":"+ c.getMinute() +":"+ c.getSecond();
        return "";
    }
    
    private String toDateString(XMLGregorianCalendar c) {
        if(c != null)
            return c.getDay() +"-"+ c.getMonth() +"-"+ c.getYear();
        return "";
    }
}
